/*
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2023-10-19 16:21:04
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2023-10-22 18:05:32
 */
import { Injectable } from '@nestjs/common';
import { BaseArea } from '../../entity/baseArea.entity'
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm/repository/Repository';
import { In } from 'typeorm';
type T = /*unresolved*/ any

@Injectable()
export class BaseAreaService {
    constructor(
        @InjectRepository(BaseArea)
    private readonly baseAreaRepository: Repository<BaseArea>) { }
    //查找省市县区域服务
    async findAndCountBy(baseArea: BaseArea): Promise<T> {
        console.log(baseArea, '111-222')
        try {
            const res = await this.baseAreaRepository.findAndCountBy(baseArea)
         console.log(baseArea,'333')
         const [result, total] = res;
          console.log('输出res:',result)
        return {
            total,
            list:result
        };
        } catch (error) {

          console.log('输出res:',error)
        return {
            total:0,
            list:[]
        };
        }

    }

     //查找省市县区域服务
    async findAndCountByArrayCodeId(baseArea:Array<T>): Promise<T> {
        console.log(baseArea, '111-222')
        try {
            const res = await this.baseAreaRepository.findBy({ codeid: In(baseArea) });
           console.log(res);
        return {
            total:res.length,
            list:res
        };
        } catch (error) {

          console.log('输出res:',error)
        return {
            total:0,
            list:[]
        };
        }

    }

     //查找省市县区域服务
    async findAndCountByArrayParentId(baseArea:Array<T>): Promise<T> {
        console.log(baseArea, '111-222')
        try {
            const res = await this.baseAreaRepository.findBy({ parentid: In(baseArea) });
           console.log(res);
        return {
            total:res.length,
            list:res
        };
        } catch (error) {

          console.log('输出res:',error)
        return {
            total:0,
            list:[]
        };
        }

    }
    async findAndAllProvince(): Promise<T> {
        try {
            const res = await this.baseAreaRepository.find({
                where: {
                    parentid:0
                }
            });
        //    console.log('输出验证：',res);
        return {
            total:res.length,
            list:res
        };
        } catch (error) {
          console.log('输出res:',error)
        return {
            total:0,
            list:[]
        };
        }

     }


}
